package com.supersoft.framework.common.helper;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * Created by Jinzhe on 2016/12/8.
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response<T> implements Serializable {

    @Getter
    @Setter
    private int code;

    @Getter
    @Setter
    private String message;

    @Getter
    @Setter
    private T body;

    private Response(ResponseMessage responseMessage) {
        this.code = responseMessage.getCode();
        this.message = responseMessage.getMessage();
    }


    private Response(ResponseMessage responseMessage, T body) {
        this.code = responseMessage.getCode();
        this.message = responseMessage.getMessage();
        this.body = body;
    }

    public static <T> Response<T> success() {
        return new Response<>(ResponseMessage.SUCCESS);
    }

    public static <T> Response<T> error() {
        return new Response<>(ResponseMessage.ERROR);
    }

    public static <T> Response<T> error(ResponseMessage responseMessage) {
        return new Response<>(responseMessage);
    }


    public static <T> Response<T> success(T body) {
        return new Response<>(ResponseMessage.SUCCESS, body);
    }
}
